package com.xvxingan.utils;
import java.util.Arrays;
public class CheckUtil {
	/**
	 * 微信接入时使用 验证signature
	 * @param signature
	 * @param timestamp
	 * @param nonce
	 * @return
	 */
	public static boolean checkSignature(String signature,String timestamp,String nonce){
		//先对参数自然排序
		String[] arr = new String[]{CommonUtil.getWEIXIN_AUTHTOKEN(),timestamp,nonce};
 		Arrays.sort(arr);
		//再将字符串拼接在一起进行sha1加密
 		StringBuffer content = new StringBuffer();
		for(int i=0;i<arr.length;i++){
			content.append(arr[i]);
		}
		//sha1
		String temp="";
		try {
			temp = EncryptUtil.SHA1Encode(content.toString());
		} catch (Exception e) {
 			e.printStackTrace();
		}
		//将加密结果和signature进行对比
		return temp.equals(signature);
	}
}
